﻿/*
BF3Rcon.NET, provides a .NET implementation of BF3's RCON interface.
Copyright (C) 2011 agentwite, Timi, Unseen, AlCapwn

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

You can contact us at http://bf3rcon.codeplex.com/.
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System.Net.Battlefield3
{
    //internal extension methods will go into this file
    static class Extensions
    {
        /// <summary>
        /// Determines if a string has a value.
        /// </summary>
        /// <param name="str">The string that is being tested.</param>
        /// <returns>True if the string is not null or empty.</returns>
        internal static bool HasValue(this string str)
        {
            return !string.IsNullOrEmpty(str);
        }

        /// <summary>
        /// Converts a byte array into a hexadecimal string.
        /// </summary>
        /// <param name="bytes">An array of bytes to convert.</param>
        /// <returns>A hexadecimal string containing converted from the byte array.</returns>
        internal static string ToHexString(this byte[] bytes)
        {
            StringBuilder sb = new StringBuilder(bytes.Length * 2);
            for (int i = 0; i < bytes.Length; i ++)
            {
                //fxcop says to supply an iformatprovider
                sb.Append(bytes[i].ToString("x2",
                    System.Globalization.CultureInfo.GetCultureInfo("en-US")));
            }
            return sb.ToString();
        }
    }

    //if we later decide to make public extensions, they'll go into another class
}
